// This file configures the development web server
// which supports hot reloading and synchronized testing.

// Require Browsersync along with webpack and middleware for it
import browserSync from 'browser-sync';
// Required for react-router browserHistory
// see https://github.com/BrowserSync/browser-sync/issues/204#issuecomment-102623643
import historyApiFallback from 'connect-history-api-fallback';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import webpackConfig from '../webpack/webpack.config.local';

// const webpackConfig = getDevConfig();
const bundler = webpack(webpackConfig);

const bs = browserSync.create();

const nodemon = require('nodemon');
// nodemon({
//     script: 'server/bin/local',
//     "ignore": ["src/**"]
// }).on('start', function () {
    // Run Browsersync and use middleware for Hot Module Replacement
    bs.init({
        port: 4000,
        // server: {
        //     baseDir: 'src'
        // },
        //使用本地主机地址与端口
        proxy: "localhost:8105",
        //     {
        //     target: "localhost:8105",
        //     reqHeaders: function (config) {
        //         console.log(config)
        //         return {
        //             "host":            'localhost:8105',
        //             "accept-encoding": "identity",
        //             "agent":           false
        //         };
        //     }
        // },
// disable for https://github.com/ant-design/ant-design/issues/2744
        ghostMode: false,
        middleware: [
            webpackDevMiddleware(bundler, {
                // Dev middleware can't access config, so we provide publicPath
                // publicPath: webpackConfig.output.publicPath,

                // pretty colored output
                stats: {colors: true},

                // Set to false to display a list of each file that is being bundled.
                noInfo: true

                // for other settings see
                // http://webpack.github.io/docs/webpack-dev-middleware.html
            }),

            // bundler should be the same as above
            webpackHotMiddleware(bundler)
            // ,
            // historyApiFallback()
            // ,function (req, res, next) {
            //     console.log("Hi from middleware");
            //     next();
            // }
        ],

        // use proxy for server-render

        // no need to watch '*.js' here, webpack will take care of it for us,
        // including full page reloads if HMR won't work
        files: [
            'src/**'//, 'server/**'
        ]
    }, function () {
        console.log("browser refreshed.");
    });
// });
